# jQuery Mobile Tables

« Previous
Next Chapter »

## Responsive Tables

Responsive design is useful when you want the content of your mobile web page to respond to the user's device, such as its screen size and orientation.

With a simple class name, jQuery Mobile is aware of the user's available screen size and automatically resizes itself to show content that is relevant for that particular user.

Responsive tables allow us to display a large set of tabular data that will look attractive for both mobiles and desktops.

There are two types of responsive tables: reflow and column toggle.

## Reflow Table

The reflow mode positions the table data horizontally until it reaches a minimum size, then all rows are grouped together vertically.

Create a table, add the data-role="table" and a class of "ui-responsive" on the <table> element:

## Example

<table data-role="table" class="ui-responsive">
Try it yourself »

| For the responsive table to work correctly, you must include the <thead> and <tbody> elements. Do not use rowspan or colspan attributes; they are not supported in responsive tables.

## Column Toggle Table

The "column toggle" mode will hide columns when there is not enough width to display the data.

To create a column toggle table, add the following to the <table> element:

<table data-role="table" data-mode="columntoggle" class="ui-responsive" id="myTable">

By default, jQuery Mobile will hide columns from the right side of the table. However, you are allowed to specify which column that should be hidden or shown in a specific order. Add the data-priority attribute to the table's header (<th>) and specify a number between 1 (highest priority) to 6 (lowest priority):

<th>I will never be hidden</th>
<th data-priority="1">I am very important - I will probably not be hidden</th>
<th data-priority="3">I am less important - I could be hidden</th>
<th data-priority="5">I am not that important - there is a good chance that I will be hidden</th>

| If you do not specify a priority for a column, the column will be persistent and not available for hiding.

Put it all together and you have created a column toggle table! Notice that the framework automatically adds a button in the top right corner of the table. This lets the user to choose which column to display in the table:

## Example

<table data-role="table" data-mode="columntoggle" class="ui-responsive" id="myTable">
<thead>
<tr>
<th data-priority="6">CustomerID</th>
<th>CustomerName</th>
<th data-priority="1">ContactName</th>
<th data-priority="2">Address</th>
<th data-priority="3">City</th>
<th data-priority="4">PostalCode</th>
<th data-priority="5">Country</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>Alfreds Futterkiste</td>
<td>Maria Anders</td>
<td>Obere Str. 57</td>
<td>Berlin</td>
<td>12209</td>
<td>Germany</td>
</tr>
</tbody>
</table>
Try it yourself »

To change the toggle table button text, use the data-column-btn-text attribute:

## Example

<table data-role="table" data-mode="columntoggle" class="ui-responsive" data-column-btn-text="Click me to hide or show columns!" id="myTable">
Try it yourself »

## Styling Tables

Use the "ui-shadow" class to add shadows to the table:

## Add shadow

<table data-role="table" data-mode="columntoggle" class="ui-responsive ui-shadow" id="myTable">
Try it yourself »

For further table styling, use CSS:

## Add a bottom border to all table rows

<style>
tr {
border-bottom: 1px solid #d6d6d6;
}
</style>
Try it yourself »

## Add a bottom border to all <th> elements and a background color to all even table rows

<style>
th {
border-bottom: 1px solid #d6d6d6;
}
tr:nth-child(even) {
background: #e9e9e9;
}
</style>
Try it yourself »
« Previous
Next Chapter »

### WEB HOSTING

UK Reseller Hosting

### WEB BUILDING

FREE Website BUILDER Free HTML5 Templates

### W3SCHOOLS EXAMS

HTML, CSS, JavaScript, PHP, jQuery, XML, and ASP Certifications

### SHARE THIS PAGE

### Color Picker

### HTML/CSS

HTML Tutorial HTML5 Tutorial CSS Tutorial CSS3 Tutorial Bootstrap Tutorial

### JavaScript

JavaScript Tutorial jQuery Tutorial jQuery Mobile Tutorial AngularJS Tutorial AJAX Tutorial JSON Tutorial

### Graphics

Canvas Tutorial SVG Tutorial Google Maps Tutorial

### Server Side

SQL Tutorial PHP Tutorial ASP Tutorial ASP.NET Tutorial VBScript Tutorial AppML Tutorial

### Web

Web Building Web Statistics Web Certification

### XML

XML Tutorial DTD Tutorial Schema Tutorial XML DOM Tutorial XPath Tutorial XSLT Tutorial XQuery Tutorial XSL-FO Tutorial RSS Tutorial WSDL Tutorial

### HTML/CSS

HTML Tag Reference HTML Event Reference HTML Color Reference CSS 1,2,3 Reference Bootstrap Reference

### JavaScript

JavaScript Reference HTML DOM Reference jQuery Reference jQuery Mobile Reference Google Maps Reference

### Server Side

PHP Reference SQL Reference ASP Reference VBScript Reference Razor Reference ASP.NET Reference

### XML

XML DOM Reference XSLT Reference XSL-FO Reference XPath Reference XQuery Reference Schema Reference RSS Reference SVG Reference

### HTML Charsets

HTML Character Sets HTML ASCII HTML ANSI HTML Windows-1252 HTML ISO-8859-1 HTML Symbols HTML UTF-8

### HTML/CSS

HTML Examples CSS Examples

### Browser Scripting

JavaScript Examples HTML DOM Examples jQuery Examples jQuery Mobile Examples AngularJS Examples AJAX Examples

### Server Scripting

PHP Examples ASP Examples VBScript Examples Razor Examples .NET Examples

### XML Languages

XML Examples DTD Examples XML DOM Examples XSL Examples XSLT Examples XPath Examples XQuery Examples Schema Examples RSS Examples SVG Examples